// wenshidu/kaohe_list/kaohe_list.js
let app = getApp()
let yuming = app.globalData.yuming
const request = require('../../config/request');
Page({
  ...request,
  /**
   * 页面的初始数据
   */
  data: {
    yuming: yuming,
    title: '考核规则',
    heights: '',
  },
  gonggao(e) {
    var url = e.currentTarget.dataset.yj_type
    wx.showLoading({
      title: '正在打开中',
    })
    var hou = url.slice(24)
    console.log(hou)
    var s = hou.indexOf(".")
    var type = hou.substring(s + 1) //下划线之后
    console.log(type)
    // var url = url.slice 
    var that = this
    wx.downloadFile({
      url: url,
      success(res) {
        var filePath = res.tempFilePath
        console.log(url)
        wx.openDocument({
          filePath: filePath,
          fileType: type,
          success: function (res) {
            wx.hideLoading({
              success: (res) => {},
            })
          },
          fail(err) {
            console.log(err)
            wx.hideLoading({
              success: (res) => {},
            })
            wx.showToast({
              title: '打开失败',
              icon: 'none'
            })
          }
        })
      },
      fail(err) {
        console.log(22)
        wx.hideLoading({
          success: (res) => {},
        })
        wx.showToast({
          title: '打开失败',
          icon: 'none'
        })
      }
    })
  },
  // 返回
  backs() {
    wx.navigateBack({
      delta: 0
    })
  },
  gong_lit() {
    this.myRequest(yuming + 'Jinghexincheng/jhxc_shop_kaohe_list', {}, "POST").then(res => {
      var data = res.data.data
      data.forEach(item => {
        item.type = item.fileurl.slice(-5)
      })
      this.setData({
        gonglist: data
      })
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      heights: wx.getMenuButtonBoundingClientRect().top + 5,
      gong_xia: wx.getMenuButtonBoundingClientRect().top + 150,
      title:options.title
    })
    this.gong_lit()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})